
package View;

import Module.ResourceProject;
import Module.Resource;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.ArrayList;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JTextField;

/**
 *
 * @author CCD gruppe 2
 */
public class ResourceToProjectFrame extends javax.swing.JFrame {

    private javax.swing.JTextField FromeDateTextField;
    private javax.swing.JButton addResourceButton;
    private javax.swing.JList availableResouceList;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton newResourceButton;
    private javax.swing.JButton removeResourceButton;
    private javax.swing.JButton saveButton;
    private javax.swing.JList selectedResourcesList;
    private javax.swing.JTextField toDateTextField;
    private DefaultListModel availableResourceListModel;
    private DefaultListModel selectedResourceListModel;
    ArrayList<Resource> availableResources = new ArrayList<Resource>();
    ArrayList<Resource> selectedResources = new ArrayList<Resource>();
    ArrayList<ResourceProject> resourceProject = new ArrayList<ResourceProject>();

    /** Creates new form ResourceToProjectFrame */
    public ResourceToProjectFrame() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        availableResouceList = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        selectedResourcesList = new javax.swing.JList();
        FromeDateTextField = new javax.swing.JTextField();
        toDateTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        addResourceButton = new javax.swing.JButton();
        removeResourceButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        newResourceButton = new javax.swing.JButton();
        availableResourceListModel = new DefaultListModel();
        selectedResourceListModel = new DefaultListModel();
        availableResouceList.setModel(availableResourceListModel);
        selectedResourcesList.setModel(selectedResourceListModel);

        FromeDateTextField.setMinimumSize(new java.awt.Dimension(94, 28));
        FromeDateTextField.setPreferredSize(new java.awt.Dimension(94, 28));

        toDateTextField.setMinimumSize(new java.awt.Dimension(94, 28));
        toDateTextField.setPreferredSize(new java.awt.Dimension(94, 28));


        jLabel1.setText("Tilgjengelige ressurser:");

        jScrollPane1.setViewportView(availableResouceList);

        jLabel2.setText("Valgte ressurser:");

        
        jScrollPane2.setViewportView(selectedResourcesList);

        jLabel3.setText("Dato for bruk av ressurs");

        jLabel4.setText("-");

        addResourceButton.setText("Legg til");

        removeResourceButton.setText("Fjern");

        saveButton.setText("Lagre");

        newResourceButton.setText("Ny ressurs");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jScrollPane1)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
                    .add(removeResourceButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 139, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(addResourceButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 141, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(layout.createSequentialGroup()
                        .add(FromeDateTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(2, 2, 2)
                        .add(jLabel4)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(toDateTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jLabel3)
                    .add(newResourceButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 144, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(saveButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 146, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel2)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 153, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(FromeDateTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel4)
                            .add(toDateTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(18, 18, 18)
                        .add(addResourceButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(removeResourceButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 30, Short.MAX_VALUE)
                        .add(newResourceButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(saveButton))
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
        setCenterPos(this);
    }// </editor-fold>
    /**
     * A method that clears the frame.
     */
    public void clear(){
        resourceProject.clear();
        availableResources.clear();
        selectedResources.clear();
        availableResourceListModel.removeAllElements();
        selectedResourceListModel.removeAllElements();
    }

    private static void setCenterPos(JFrame frame) {
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (int) ((screen.getWidth() - frame.getWidth()) / 2);
        int y = (int) ((screen.getHeight() - frame.getHeight()) / 2);
        frame.setLocation(x, y);
    }

    /*
     * Getters and setters
     */

    public JTextField getFromeDateTextField() {
        return FromeDateTextField;
    }

    public void setFromeDateTextField(JTextField FromeDateTextField) {
        this.FromeDateTextField = FromeDateTextField;
    }

    public JButton getAddResourceButton() {
        return addResourceButton;
    }

    public void setAddResourceButton(JButton addResourceButton) {
        this.addResourceButton = addResourceButton;
    }

    public JList getAvailableResouceList() {
        return availableResouceList;
    }

    public void setAvailableResouceList(JList availableResouceList) {
        this.availableResouceList = availableResouceList;
    }

    public DefaultListModel getAvailableResourceListModel() {
        return availableResourceListModel;
    }

    public void setAvailableResourceListModel(DefaultListModel availableResourceListModel) {
        this.availableResourceListModel = availableResourceListModel;
    }

    public JButton getNewResourceButton() {
        return newResourceButton;
    }

    public void setNewResourceButton(JButton newResourceButton) {
        this.newResourceButton = newResourceButton;
    }

    public JButton getRemoveResourceButton() {
        return removeResourceButton;
    }

    public void setRemoveResourceButton(JButton removeResourceButton) {
        this.removeResourceButton = removeResourceButton;
    }

    public JButton getSaveButton() {
        return saveButton;
    }

    public void setSaveButton(JButton saveButton) {
        this.saveButton = saveButton;
    }

    public DefaultListModel getSelectedResourceListModel() {
        return selectedResourceListModel;
    }

    public void setSelectedResourceListModel(DefaultListModel selectedResourceListModel) {
        this.selectedResourceListModel = selectedResourceListModel;
    }

    public JList getSelectedResourcesList() {
        return selectedResourcesList;
    }

    public void setSelectedResourcesList(JList selectedResourcesList) {
        this.selectedResourcesList = selectedResourcesList;
    }

    public JTextField getToDateTextField() {
        return toDateTextField;
    }

    public void setToDateTextField(JTextField toDateTextField) {
        this.toDateTextField = toDateTextField;
    }

    public ArrayList<Resource> getAvailableResources() {
        return availableResources;
    }

    public void setAvailableResources(ArrayList<Resource> availableResources) {
        this.availableResources = availableResources;
    }

    public ArrayList<Resource> getSelectedResources() {
        return selectedResources;
    }

    public void setSelectedResources(ArrayList<Resource> selectedResources) {
        this.selectedResources = selectedResources;
    }

    public ArrayList<ResourceProject> getResourceProject() {
        return resourceProject;
    }

    public void setResourceProject(ArrayList<ResourceProject> resourceProject) {
        this.resourceProject = resourceProject;
    }

}
